package yur.wedding.modules.sys.controller;

import java.util.Arrays;
import java.util.Map;


import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import yur.wedding.modules.sys.entity.SysDocshareEntity;
import yur.wedding.modules.sys.service.SysDocshareService;
import yur.wedding.utils.PageUtils;
import yur.wedding.utils.R;
import yur.wedding.validator.ValidatorUtils;


/**
 * 文档权限
 *
 * @author Yur
 * @email ${email}
 * @date 2022-08-16 07:31:41
 */
@RestController
@RequestMapping("sys/sysdocshare")
public class SysDocshareController {
    @Autowired
    private SysDocshareService sysDocshareService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("sys:sysdocshare:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = sysDocshareService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("sys:sysdocshare:info")
    public R info(@PathVariable("id") Long id){
        SysDocshareEntity sysDocshare = sysDocshareService.getById(id);

        return R.ok().put("sysDocshare", sysDocshare);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("sys:sysdocshare:save")
    public R save(@RequestBody SysDocshareEntity sysDocshare){
        sysDocshareService.save(sysDocshare);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("sys:sysdocshare:update")
    public R update(@RequestBody SysDocshareEntity sysDocshare){
        ValidatorUtils.validateEntity(sysDocshare);
        sysDocshareService.updateById(sysDocshare);
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("sys:sysdocshare:delete")
    public R delete(@RequestBody Long[] ids){
        sysDocshareService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

    /**
     * 获取文档有那些权限
     */
    @RequestMapping("/documentGetShareList/{dbgyId}")
    @RequiresPermissions("sys:sysdocshare:documentGetShareList")
    public R documentGetShareList(@PathVariable("dbgyId") Long dbgyId,@RequestParam Map<String, Object> params) {

        PageUtils page = sysDocshareService.getShareList(dbgyId,params);
        return R.ok().put("page", page);
    }

}
